package com.training1.api.controller;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.training1.core.common.global.Global;
import com.training1.core.dto.APIAccountIncomeDto;
import com.training1.core.entity.NodeAccountEntity;
import com.training1.core.modules.dao.SystemSettingsDao;
import com.training1.core.modules.service.APIAccountIncomeService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;

@Api(value = "/api/accountincome", description = "演示个人中心获取被推荐人列表") // Swagger annotation
@RestController
@RequestMapping("/api/accountincome")
public class APIAccountIncomeController {
	private static final Logger logger = LoggerFactory.getLogger(APIAccountIncomeController.class);
	
	@Resource
	private APIAccountIncomeService aaiService;
	@Resource
	private SystemSettingsDao systemSettingDao;
	
	@ApiOperation(value = "api个人中心获取被推荐人列表, 第一个参数是会员手机号码，第二个参数是开始记录数")
	@RequestMapping(value = "/appincome", method = RequestMethod.GET)
	public APIAccountIncomeDto<Object> accountincome( @RequestParam String cellPhone,@RequestParam int begin) {
		logger.info("客户端会员个人中心获取被推荐人列表, cellphone : " + cellPhone);
		APIAccountIncomeDto<Object> dto = new APIAccountIncomeDto<Object>();
		String total = aaiService.getTotalIncome(cellPhone);
		if(total != null){
			if(begin > 0 || begin == 0){
				dto.setIncomeSUM(total);
				String recmdIncomeSUM = aaiService.getRecommendSum(cellPhone);
				if(recmdIncomeSUM == null || recmdIncomeSUM == "0"){
					dto.setErrorCode("1");
					dto.setMessage("您还没有推荐信息，加油哦");
				}else{
					dto.setRecmdIncomeSUM(recmdIncomeSUM);
					Map<String,Object> map = new HashMap<>();
					map.put("cellPhone", cellPhone);
					map.put("begin", begin);
					dto.setData(aaiService.getRecommendedList(map));
					dto.setErrorCode("0");
					dto.setStatus(1);
					dto.setMessage("");
				}
			}else{
				dto.setErrorCode("1");
				dto.setStatus(0);
				dto.setMessage("输入的开始查询数必须大于等于0");
			}
		}else{
			dto.setErrorCode("1");
			dto.setStatus(0);
			dto.setMessage("账号不存在或已被锁定，请联系平台管理员");
		}
		
		return dto;
	}
}